<?php

namespace addons\yexam;

use app\common\library\Menu;
use think\Addons;

/**
 * 插件
 */
class Yexam extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name'    => 'yexam',
                'title'   => '考试系统',
                'icon'    => 'fa fa-graduation-cap',
                'sublist' => [
                    [
                        "name"    => "yexam/subject",
                        "title"   => "科目管理",
                        'icon'    => 'fa fa-map-marker',
                        'sublist' => [
                            ["name" => "yexam/subject/index", "title" => "查看",],
                            ["name" => "yexam/subject/add", "title" => "添加"],
                            ["name" => "yexam/subject/edit", "title" => "编辑"],
                            ["name" => "yexam/subject/del", "title" => "删除"],
                            ["name" => "yexam/subject/multi", "title" => "批量更新"],
                        ]
                    ],
                    [
                        "name"    => "yexam/ad",
                        "title"   => "轮播图管理",
                        'icon'    => 'fa fa-photo',
                        'sublist' => [
                            ["name" => "yexam/ad/index", "title" => "查看",],
                            ["name" => "yexam/ad/add", "title" => "添加"],
                            ["name" => "yexam/ad/edit", "title" => "编辑"],
                            ["name" => "yexam/ad/del", "title" => "删除"],
                            ["name" => "yexam/ad/multi", "title" => "批量更新"],
                        ]
                    ],
                    [
                        "name"    => "yexam/unit",
                        "title"   => "章节练习",
                        'icon'    => 'fa fa-braille',
                        'sublist' => [
                            ["name" => "yexam/unit/index", "title" => "查看",],
                            ["name" => "yexam/unit/add", "title" => "添加"],
                            ["name" => "yexam/unit/edit", "title" => "编辑"],
                            ["name" => "yexam/unit/del", "title" => "删除"],
                            ["name" => "yexam/unit/multi", "title" => "批量更新"],
                            [
                                "name"    => "yexam/question",
                                "title"   => "题目管理",
                                'ismenu'  => 0,
                                'sublist' => [
                                    ["name" => "yexam/question/index", "title" => "查看",],
                                    ["name" => "yexam/question/add", "title" => "添加"],
                                    ["name" => "yexam/question/edit", "title" => "编辑"],
                                    ["name" => "yexam/question/del", "title" => "删除"],
                                    ["name" => "yexam/question/multi", "title" => "批量更新"],
                                    ["name" => "yexam/question/import", "title" => "导入题目"],
                                ]
                            ],


                        ]
                    ],
                    [
                        "name"    => "yexam/exam",
                        "title"   => "考试管理",
                        'icon'    => 'fa fa-graduation-cap',
                        'sublist' => [
                            ["name" => "yexam/exam/index", "title" => "查看",],
                            ["name" => "yexam/exam/add", "title" => "添加"],
                            ["name" => "yexam/exam/edit", "title" => "编辑"],
                            ["name" => "yexam/exam/del", "title" => "删除"],
                            ["name" => "yexam/exam/multi", "title" => "批量更新"],
                            ["name" => "yexam/exam/question", "title" => "考试题目管理"],
                            ["name" => "yexam/exam/sel_question", "title" => "抽题组卷"],
                            ["name" => "yexam/exam/import", "title" => "导入题目"],
                            ["name" => "yexam/exam/user_log", "title" => "考试记录"],
                            ["name" => "yexam/exam/error_user_log", "title" => "错题记录"],
                        ]
                    ],
                    [
                        "name"    => "yexam/library",
                        "title"   => "历年真题",
                        'icon'    => 'fa fa-list-alt',
                        'sublist' => [
                            ["name" => "yexam/library/index", "title" => "查看",],
                            ["name" => "yexam/library/add", "title" => "添加"],
                            ["name" => "yexam/library/edit", "title" => "编辑"],
                            ["name" => "yexam/library/del", "title" => "删除"],
                            ["name" => "yexam/library/multi", "title" => "批量更新"],
                            [
                                "name"    => "yexam/library_question",
                                "title"   => "题目管理",
                                'ismenu'  => 0,
                                'sublist' => [
                                    ["name" => "yexam/library/question", "title" => "查看",],
                                    ["name" => "yexam/library/addquestion", "title" => "添加"],
                                    ["name" => "yexam/library/editquestion", "title" => "编辑"],
                                    ["name" => "yexam/library/delquestion", "title" => "删除"],
                                    ["name" => "yexam/library/import", "title" => "导入题目"],
                                ]
                            ],
                        ]
                    ],
                ]
            ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete("yexam");
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable("yexam");
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable("yexam");
        return true;
    }

}
